import 'package:dio/dio.dart';
import 'package:village_android/config/contants.dart';
import 'package:village_android/utils/http_utlis.dart';
import 'dart:async';
import 'dart:io';
import 'service_url.dart';
import 'dart:convert' as convert;

//获取新闻列表
Future getNewsList() async {
  try {
    Response response;
    Dio dio = new Dio();
//    dio.option.header =
//    var params = {"type":1};
    response = await dio.get(newsAPI + '/list');
    if (response.statusCode == 200) {
      return response;
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {}
}

//获取banner列表
Future getBannerList() async {
  try {
    Response response;
    Dio dio = new Dio();
//    dio.option.header =
//    var params = {"type":1};
    response = await dio.get(bannerAPI + '/list');
    if (response.statusCode == 200) {
      return response;
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {}
}


//获取新闻列表
Future getUserData(userId) async {
  try {
    Response response;
    Dio dio = new Dio();
//    FormData formData = new FormData.from({
//      "userId": userId,
//    });
    response = await dio.get(BaseUrl.url +  "/mgr/getUserInfo", queryParameters: {K_USER_ID: userId});
    if (response.statusCode == 200) {
      String jsonString = convert.jsonEncode(response.data["data"]);
      return jsonString;
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {

  }
}

Future getRegisterDatas() async {
  return Future.wait([getDeptList(), getVillageNameList()]);
}


//获取户代表
Future getVillageNameList() async {
  try {
    Response response;
    Dio dio = new Dio();
    response = await dio.get(BaseUrl.url +  "/sysConfig/list?code=villageName");
    if (response.statusCode == 200) {
      if(response.data == null){
        return null;
      }
      return response.data["data"];
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {
  }
}
//获取生产队列表
Future getDeptList() async {
  try {
    Response response;
    Dio dio = new Dio();
    response = await dio.get(BaseUrl.url +  "/dept/list");
    if (response.statusCode == 200) {
      if(response.data == null){
        return null;
      }
      return response.data["data"];
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {
  }
}
//获取新闻列表
Future getSysConfigList(dictTypeId) async {
  try {
    Response response;
    Dio dio = new Dio();
//    FormData formData = new FormData.from({
//      "userId": userId,
//    });
    var params = "";
    if(dictTypeId!=null){
      params = "?dictTypeId=" + dictTypeId.toString();

    }

    response = await dio.get(BaseUrl.url +  "/sysConfig/list" + params);
    if (response.statusCode == 200) {
//      String jsonString = convert.jsonEncode(response.data["data"]);
      return response.data["data"];
    } else {
      throw Exception("数据为空");
    }
  } catch (e) {

  }
}